package com.xwh.article.controller;

import cn.hutool.core.lang.tree.Tree;
import com.xwh.article.entity.SoftwareType;
import com.xwh.article.service.SoftwareTypeService;
import com.xwh.core.controller.BaseController;
import com.xwh.core.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xwh
 **/

@RestController
@RequestMapping("/softwareType")
@Tag(name = "应用:软件分类管理")
@Slf4j
@RequiredArgsConstructor
public class SoftwareTypeController extends BaseController {

    final SoftwareTypeService softwareTypeService;

    @Operation(summary = "新增一个软件分类")
    @PostMapping("/save")
    public Result save(@RequestBody SoftwareType softwareType) {
        softwareTypeService.add(softwareType);
        return success();
    }

    @Operation(summary = "获取全部软件分类列表")
    @GetMapping("/list")
    public Result list() {
        List<Tree<String>> trees = softwareTypeService.listTree();
        return success().add(trees);
    }

    @Operation(summary = "删除一个软件分类")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        softwareTypeService.removeById(id);
        return success();
    }

    @Operation(summary = "修改一个软件分类")
    @PutMapping("/update")
    public Result update(@RequestBody SoftwareType softwareType) {
        softwareTypeService.updateById(softwareType);
        return success();
    }
}
